﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Hetymine.Executioner {
    /// <summary>
    /// Interaction logic for Display.xaml
    /// </summary>
    public partial class Display : Window {
        private DispatcherTimer _Timer;
        private static int _Count = 0;
        private static int _Index = -1;
        public Display() {
            InitializeComponent();         
            this.Time = 2100;
            this._Timer = new DispatcherTimer();
            this._Timer.Tick += new EventHandler(_Timer_Tick);

            Styles.OuterBorder(this.brdOuter);
            Styles.InnerBorder(this.brdInner);
            Styles.TextBox(this.txtDisplay);
            this.txtDisplay.FontSize = this.txtDisplay.FontSize + (this.txtDisplay.FontSize * 0.15);
        }
        public string Text {
            get { return txtDisplay.Text; }
            set { txtDisplay.Text = value; }
        }
        public int Time { get; set; }

        public new void Show() {            
            this._Timer.Interval = TimeSpan.FromMilliseconds(this.Time);
            this._Timer.Start();

            base.Show();

            int margin = Executioner.Config.GetInt("Appearance", "Margin", 10);

            if (Display._Count == 0) {
                Display._Index = -1;
            }

            ++Display._Count;
            ++Display._Index;

            margin += (int)(Display._Index * (margin + this.ActualHeight));

            Point p = Styles.Position(this.ActualWidth, this.ActualHeight, "centre top", margin);

            this.Left = p.X;
            this.Top = p.Y;

            this.Activate();
        }

        private void _Timer_Tick(object sender, EventArgs e) {
            this._Timer.Stop();
            --Display._Count;
            this.Close();
        }
    }
}
